package com.mes.schedule.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.mes.common.domain.BasicModel;


/**
 * 工序任务之间关系
 * date: Jun 22, 2015 5:05:13 PM <br/>  
 * @author Administrator  
 * @version   
 * @since JDK 1.6
 * @add Annotation cswen 2017/3/15
 */

@Entity
@org.hibernate.annotations.Entity(dynamicInsert=false,dynamicUpdate=false)
@Table(name = "T_SCHEDULE_LINKS")
public class SOperationLink extends BasicModel implements Serializable {

	private static final long serialVersionUID = 1L;
	
	/**
	 * LINKTYPE
	 */
	public final static int LINKTYPE_FTS = 1;
	public final static int LINKTYPE_FTF = 2;
	public final static int LINKTYPE_STS = 3;
	public final static int LINKTYPE_STF = 4;

	//与locked字段合并
	//todo
	public final static int LOCKLEVEL_CANNOTBREAK = 3;
	public final static int LOCKLEVEL_CANBREAK = 1;
	
	
	@Column(name = "LINKUID")
	protected String linkUid; 
	
	@Id
	@Column(name = "SCHEDULEUID")
	protected String scheduleUid;
	
	@Id
	@Column(name = "PREDUID")
	protected String predecessorUid;
	
	@Id
	@Column(name = "SUCCUID")
	protected String successorUid;
	
	/**
	 * 前置工序任务
	 */
	@Transient
	protected  SOperationTask predOperationTask;

	/**
	 * 后置工序任务
	 */
	@Transient
	protected  SOperationTask succOperationTask;

	@Column(name = "LINKTYPE")
	protected Integer linkType;

	/**
	 * 依赖类型，如果=2表示装配齐套连接
	 */	
	@Column(name = "DEPENDTYPE")
	protected Integer dependType;	
	
	@Column(name = "LINKLAG")
	protected Integer linkLag;
	@Transient
	protected Double linkQty;
	
	@Column(name = "LOCKED")
	protected Boolean locked;
	
	
	@Transient
	protected int isIneffective;
	@Transient
	protected int lockLevel;
	//只是为了调度顺序 ScheduleOrder,不影响移动方式
	//lqm todo
	//放在这里也许有些不合适
	//将来需要换只需要修改MOVETYPE_INGORE相关处
	//表示我排完了，你才能去排
	/**
	 * 忽略移动
	 */	
	public final static int MOVETYPE_INGORE = 10;
	/**
	 * 顺序移动
	 */		
	public final static int MOVETYPE_SEQUENCE = 1;
	/**
	 * 平行移动
	 */	
	public final static int MOVETYPE_FLOW = 2;
	/**
	 * 平顺移动
	 */	
	public final static int MOVETYPE_FLOWSEQUENCE = 3;
	/**
	 * 顺序移动
	 */	
	@Column(name = "MOVETYPE")
	protected Integer moveType=MOVETYPE_SEQUENCE;
	
	/**
	 * 	每次流水移动数量
	 */
	@Column(name = "TRANSFER_QTY")
	protected Integer transferQty;
	
	@Column(name = "VIRTUALLINK")
	protected Boolean virtualLink=false;
	

	/**
	 * 	该虚拟链接是否需要保存
	 */
	@Transient
	protected boolean persistence=true;
	@Transient
	protected ScheduleScheme scheme;
	@Transient
	protected int objectState; 

	public int getObjectState() {
		return objectState;
	}

	public void setObjectState(int objectState) {
		this.objectState = objectState;
	}

	public Integer getMoveType() {
		return moveType;
	}

	public void setMoveType(Integer moveType) {
//		if(this.getLinkUid().equals("a6d33a87-889d-4349-a4a5-366f85896575"))
//		{
//			System.out.println("aaaaaa");
//		}

		this.moveType = moveType;
	}

	public ScheduleScheme getScheme() {
		return scheme;
	}

	public void setScheme(ScheduleScheme scheme) {
		this.scheme = scheme;
		if(scheme!=null)
		this.scheduleUid=scheme.getScheduleUid();
	}


	/**
	 * @return the scheduleUid
	 */
	public String getScheduleUid() {
		return scheduleUid;
	}

	/**
	 * @param scheduleUid
	 *            the scheduleUid to set
	 */
	public void setScheduleUid(String scheduleUid) {
		this.scheduleUid = scheduleUid;
	}

	/**
	 * @return the predecessorUid
	 */
	public String getPredecessorUid() {
		return predecessorUid;
	}

	/**
	 * @param predecessorUid
	 *            the predecessorUid to set
	 */
	public void setPredecessorUid(String predecessorUid) {
		this.predecessorUid = predecessorUid;
	}

	/**
	 * @return the successorUid
	 */
	public String getSuccessorUid() {
		return successorUid;
	}

	/**
	 * @param successorUid
	 *            the successorUid to set
	 */
	public void setSuccessorUid(String successorUid) {
		this.successorUid = successorUid;
	}





	public Integer getLinkType() {
		return linkType;
	}

	public void setLinkType(Integer linkType) {
		this.linkType = linkType;
	}

	/**
	 * @return the lockLevel
	 */
	public int getLockLevel() {
		return lockLevel;
	}

	/**
	 * @param lockLevel
	 *            the lockLevel to set
	 */
	public void setLockLevel(int lockLevel) {
		this.lockLevel = lockLevel;
	}



	public Integer getLinkLag() {
		return linkLag;
	}

	public void setLinkLag(Integer linkLag) {
		this.linkLag = linkLag;
	}

	/**
	 * @return the isIneffective
	 */
	public int getIsIneffective() {
		return isIneffective;
	}

	/**
	 * @param isIneffective
	 *            the isIneffective to set
	 */
	public void setIsIneffective(int isIneffective) {
		this.isIneffective = isIneffective;
	}

	/**
	 * @return the predOperationTask
	 */
	public SOperationTask getPredOperationTask() {
		return predOperationTask;
	}

	/**
	 * @param predOperationTask
	 *            the predOperationTask to set
	 */
	public void setPredOperationTask(SOperationTask predOperationTask) {
		this.predOperationTask = predOperationTask;
		this.predecessorUid=predOperationTask.getTaskUid();
	}

	/**
	 * @return the succOperationTask
	 */
	public SOperationTask getSuccOperationTask() {
		return succOperationTask;
	}

	/**
	 * @param succOperationTask
	 *            the succOperationTask to set
	 */
	public void setSuccOperationTask(SOperationTask succOperationTask) {
		this.succOperationTask = succOperationTask;
		this.successorUid=succOperationTask.getTaskUid();
	}


	public Integer getTransferQty() {
		return transferQty;
	}

	public void setTransferQty(Integer transferQty) {
		this.transferQty = transferQty;
	}

	public Boolean getLocked() {
		return locked;
	}

	public void setLocked(Boolean locked) {
		this.locked = locked;
	}

	public String getLinkUid() {
		return linkUid;
	}

	public void setLinkUid(String linkUid) {
		this.linkUid = linkUid;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		//lqm tod
		//hashSet就是靠hash值进行比较
		//不靠equals
		String keyString=getLinkKey();
		result = prime * result + ((keyString== null) ? 0 : keyString.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final SOperationLink other = (SOperationLink) obj;
		
		
		if (getLinkKey() == null) {
			if (other.getLinkKey() != null)
				return false;
		} else if (!getLinkKey().equals(other.getLinkKey()))
			return false;
		return true;
	}



	public Boolean getVirtualLink() {
		return virtualLink;
	}

	public void setVirtualLink(Boolean virtualLink) {
		this.virtualLink = virtualLink;
	}

	public Double getLinkQty() {
		return linkQty;
	}

	public void setLinkQty(Double linkQty) {
		this.linkQty = linkQty;
	}
	
	

	
	public  String getLinkKey()
	{
		return this.predecessorUid+"__"+this.successorUid;
	}

	public boolean isPersistence() {
		return persistence;
	}

	public void setPersistence(boolean persistence) {
		this.persistence = persistence;
	}

	public String getUuid() {
		// TODO Auto-generated method stub
		return this.linkUid;
	}

	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.setLinkUid(uuid);
	}
	
	public void destroy()
	{
		try {
			this.scheme=null;
			
			this.predOperationTask=null;
			this.succOperationTask=null;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	public Integer getDependType() {
		return dependType;
	}

	public void setDependType(Integer dependType) {
		this.dependType = dependType;
	}


}
